package com.wdj.library.controller;

import com.wdj.library.entity.MUserBook;
import com.wdj.library.entity.vo.IDVO;
import com.wdj.library.entity.vo.Result;
import com.wdj.library.inter.JwtToken;
import com.wdj.library.service.MUserBookService;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * (MUserBook)表控制层
 *
 * @author wdj
 * @since 2020-08-12 11:54:07
 */
@RestController
@RequestMapping("mUserBook")
public class MUserBookController {
    /**
     * 服务对象
     */
    @Resource
    private MUserBookService mUserBookService;

    /**
     * @Author wdj
     * @Description //TODO 借书
     * @Date 16:32 2020/8/14
     * @Param [userId, bookId]
     * @return com.wdj.library.entity.vo.Result
     **/
    @JwtToken
    @PostMapping("borrowBook")
    public Result borrowBook(Integer userId, Integer bookId){
        return mUserBookService.borrowBook(userId,bookId);
    }


    /**
     * @Author wdj
     * @Description //TODO 某个用户的借阅记录
     * @Date 16:32 2020/8/14
     * @Param
     * @return
     **/
    @JwtToken
    @GetMapping("queryByUserId")
    @ResponseBody
    public Result borrowList (Integer userId){
        return mUserBookService.borrowList(userId);
    }



    /**
     * @Author wdj
     * @Description //TODO 全部借阅记录
     * @Date 16:32 2020/8/14
     * @Param [offset, limit]
     * @return com.wdj.library.entity.vo.Result
     **/
    @JwtToken
    @GetMapping("queryAll")
    @ResponseBody
    public Result borrowAllList (Integer offset, Integer limit){
        return mUserBookService.queryAllByLimit(offset, limit);
    }


    /**
     * @Author wdj
     * @Description //TODO 归还书籍
     * @Date 16:48 2020/8/14
     * @Param [id]
     * @return com.wdj.library.entity.vo.Result
     **/
    @JwtToken
    @ResponseBody
    @PostMapping("giveBack")
    public Result giveBack(Integer id){
        return mUserBookService.giveBack(id);
    }

}